package com.ruoyi.web.controller.jl;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.base.Result;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.support.Convert;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.base.BaseController;
import com.ruoyi.jl.domain.GiveGold;
import com.ruoyi.jl.service.IGiveGoldService;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 赠送金币 控制层
 * 
 * @author wh
 * @date 2019-04-29
 */
@Slf4j
@Controller
@RequestMapping("/jl/giveGold")
public class GiveGoldController extends BaseController {
    private String prefix = "jl/giveGold";
	
	private final IGiveGoldService giveGoldService;

	@Autowired
	public GiveGoldController(IGiveGoldService giveGoldService) {
		this.giveGoldService = giveGoldService;
	}

	/**
	*  列表页
	*/
	@RequiresPermissions("jl:giveGold:view")
	@GetMapping
	public String giveGold(){
	    return prefix + "/giveGold";
	}

	/**
	 * 新增页
	 */
	@GetMapping("/add")
	public String add(){
		return prefix + "/add";
	}

	/**
	 * 编辑页
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Integer id, ModelMap mmap){
		GiveGold giveGold = giveGoldService.getById(id);
		mmap.put("giveGold", giveGold);
		return prefix + "/edit";
	}
	
	/**
	 * 查询赠送金币列表
	 */
	@RequiresPermissions("jl:giveGold:list")
	@PostMapping("/list")
	@ResponseBody
	public Result list(GiveGold giveGold){
		startPage();
        List<GiveGold> list = giveGoldService.list(giveGold);
		return Result.success(getDataTable(list));
	}

	/**
	 * 新增保存赠送金币
	 */
	@RequiresPermissions("jl:giveGold:add")
	@Log(title = "赠送金币", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public Result addSave(GiveGold giveGold){
		giveGoldService.save(giveGold);
		return Result.success();
	}

	/**
	 * 修改保存赠送金币
	 */
	@RequiresPermissions("jl:giveGold:edit")
	@Log(title = "赠送金币", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public Result editSave(GiveGold giveGold){
		giveGoldService.updateById(giveGold);
		return Result.success();
	}
	
	/**
	 * 删除赠送金币
	 */
	@RequiresPermissions("jl:giveGold:remove")
	@Log(title = "赠送金币", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public Result remove(String ids){
		Long[] longIds = Convert.toLongArray(ids);
		giveGoldService.removeByIds(Arrays.asList(longIds));
		return Result.success();
	}

	/**
	 * 导出赠送金币列表
	 */
	@RequiresPermissions("jl:giveGold:export")
	@PostMapping("/export")
	@ResponseBody
	public Result export(GiveGold giveGold){
		List<GiveGold> list = giveGoldService.list(giveGold);
		ExcelUtil<GiveGold> util = new ExcelUtil<>(GiveGold.class);
		util.exportExcel(list, "giveGold");
		return Result.success();
	}
}
